package com.boot.ys.mybatisplus.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.boot.ys.mybatisplus.entity.vo.Arlarms;
import com.boot.ys.mybatisplus.entity.vo.HeartbeatParam;
import com.boot.ys.mybatisplus.entity.vo.StateAddressParam;
import com.boot.ys.mybatisplus.entity.vo.XinTiaoParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.protocol.HTTP;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * Copyright © 2021-2022 菁锐智能. All rights reserved.
 *
 * @author ys
 * @version 1.0
 * @date 2023-09-06 14:57
 */
@Slf4j
@RestController
@RequestMapping("/recv")
@Api(tags = "测试SAM200")
public class ElectricityController {


    @ApiOperation(value = "接收报警推送地址-回调")
    @RequestMapping("/alarm")
    public void alarm(@RequestBody Arlarms alarms) {
        log.info("报警推送地址" + alarms);
    }


    @ApiOperation(value = "推送状态地址-回调")
    @RequestMapping("/status")
    public void status(@RequestBody StateAddressParam param) {
        log.info("状态推送地址" + param);
    }


    @ApiOperation(value = "心跳状态推送-回调")
    @PostMapping("/status/heartbeat")
    public void testFuture(@RequestBody XinTiaoParam param) {
        log.info("状态心跳推送" + param);
    }


    /**
     * 注册地址-增加警报的回调地址
     */
    @ApiModelProperty("注册-报警地址推送")
    @GetMapping("/register/alarmput")
    private String alarmput() {

        //装有SAM200的主机
        String url = "192.168.1.104:20433/register/alarmput";

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("url", "192.168.1.104:9009/recv/alarm");
        hashMap.put("clientid", DateUtil.today());
        hashMap.put("platformname", "gato");

        JSONObject jsonObject = new JSONObject(hashMap);
        String jsonString = jsonObject.toJSONString();

        log.info("传入的JSON数据" + jsonString);

        String post = HttpUtil.post(url, jsonString);

        log.info("请求结果" + post);
        return post;
    }


    /**
     * 注册状态-推送地址
     */
    @GetMapping("/putStatr")
    public void putStatr() {
        //装有SAM200的主机的IP
        String url = "192.168.1.104:20433/register/statusput";

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("url", "192.168.1.104:9009/recv/status");
        hashMap.put("clientid", DateUtil.today());
        hashMap.put("platformname", "gato");

        JSONObject jsonObject = new JSONObject(hashMap);
        String jsonString = jsonObject.toJSONString();

        log.info("传入的JSON数据" + jsonString);

        String post = HttpUtil.post(url, jsonString);

        log.info("请求结果" + post);
    }


    /**
     * 注册
     */

    /**
     * 获取全部的设备信息
     */
    @GetMapping("/getAllequipment")
    public String getAllequipment(){
        String result = HttpUtil.get("192.168.1.104:20433/device/list");
        log.info("获取全部的设备信息"+result);
        return result;
    }


    /**
     *  获取指定uniquecode的设备信息
     */
    @GetMapping("/getEquipmentByCode/{code}")
    public String getEquipmentByCode(@PathVariable("code") String code){
        //最后这个数字填code
        String result = HttpUtil.get("192.168.1.104:20433/device/uniquecode/"+code);
        log.info("根据设备的code获取这个设备的相关信息"+result);
        return result;
    }


    /**
     * 获取全部的通道信息
      */
    @GetMapping("/getAllChannel")
    public String getAllChannel(){
        String result = HttpUtil.get("192.168.1.104:20433/channel/list");
        log.info("获取全部的通道信息"+result);
        return result;
    }

    /**
     * 获取指定uniquecode的通道信息
     */
    @GetMapping("/getChannelByCode/{code}")
    public String getChannelByCode(@PathVariable("code") String code){
        String result = HttpUtil.get("192.168.1.104:20433/device/uniquecode/"+code);
        log.info("获取指定uniquecode的通道信息"+result);
        return result;
    }


    /**
     *
      10. 获取f5f7通道相关的点位集合
     */
    @GetMapping("/getF5F7Channer/{code}")
    public String getF5F7Channer(@PathVariable("code") String code){
        String result = HttpUtil.get("192.168.1.104:20433/f5f7/channel/points"+code);
        log.info("获取f5f7通道相关的点位集合"+result);
        return result;
    }


    /**
     * 11. 根据通道uniquecode获取地图上的点位信息
     */
    @GetMapping("/unit/{code}")
    public String unit(@PathVariable("code") String code){
        String result = HttpUtil.get("192.168.1.104:20433/map/unit/info/"+code);
        log.info("11. 根据通道uniquecode获取地图上的点位信息"+result);
        return result;
    }


    /**
     * 12. 通过通道uniquecode获取视频报警联动信息
     *
     */
    @GetMapping("/video/{code}")
    public String video(@PathVariable("code") String code){
        String result = HttpUtil.get("192.168.1.104:20433/video/alarmlink/info/"+code);
        log.info("通过通道uniquecode获取视频报警联动信息"+result);
        return result;
    }




}
